package xyz.flowlight.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import xyz.flowlight.domain.dto.LoginDTO;
import xyz.flowlight.domain.entity.User;
import xyz.flowlight.domain.response.ResponseResult;
import xyz.flowlight.mapper.UserMapper;
import xyz.flowlight.service.UserService;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * (User)表服务实现类
 *
 * @author kuailemao
 * @since 2023-10-10 19:33:44
 */
@Slf4j
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public ResponseResult userLogin(LoginDTO loginDTO) {
        // 根据用户名和密码查找用户
        User user = userMapper.findByUsernameAndPassword(loginDTO.getUsername(), loginDTO.getPassword());
        if(user!=null){
            Map<String, Object> result = new HashMap<>();
            result.put("userId", user.getUserId());
            result.put("username", user.getUsername());
            return ResponseResult.success(result);
        }
        return ResponseResult.failure("账号或密码错误");
    }
}
